﻿
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <link href="~/Content/layui/css/layui.css" rel="stylesheet" />
    <script src="~/Content/layui/layui.js"></script>
    <script src="~/Content/myjs/jquery-1.10.2.min.js"></script>
</head>
<body style="padding:40px 0 30px 80px;">
    <div class="layui-col-md8">
        <form class="layui-form layui-form-pane" lay-filter="form_add">

            <div class="layui-form-item">
                <label class="layui-form-label">编号</label>
                <div class="layui-input-inline">
                    <input type="text" name="GoodsId" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" value="" style="color:red;font-weight:600">
                </div>
                <label class="layui-form-label">名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="Name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" value="">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-inline ">
                    <select name="CategoryId" id="myCategoryId">
                        @foreach (var item in @ViewBag.category)
                        {
                            <option value=@item.Id>@item.CategoryName</option>

                        }
                    </select>

                </div>

                <label class="layui-form-label">规格</label>
                <div class="layui-input-inline ">
                    <input type="text" name="Specification" placeholder="请输入" autocomplete="off" class="layui-input" value="">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">数量</label>
                <div class="layui-input-inline">
                    <input type="text" name="Num" lay-verify="required||number" placeholder="请输入" autocomplete="off" class="layui-input" value="">
                </div>
                <label class="layui-form-label">单位</label>
                <div class="layui-input-inline ">
                    <input type="text" name="Unit" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" value="">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">单价</label>
                <div class="layui-input-inline">
                    <input type="text" name="Money" placeholder="请输入" autocomplete="off" class="layui-input" value="">
                </div>
                <label class="layui-form-label">数量</label>
                <div class="layui-input-inline ">
                    <input type="text" name="WarningNum" placeholder="请输入" autocomplete="off" class="layui-input" value="">
                </div>
            </div>






            <div class="layui-form-item" style="text-align:center;margin:0 90px 0 0;">
                <button class="layui-btn" lay-submit="" lay-filter="formDemo">确认添加</button>
            </div>
        </form>
    </div>

    <script>



        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
            var layedit = layui.layedit


            //自定义验证规则
            form.verify({
                maxlength: function (value) {
                    if (value.length >16) {
                        return '不能超过16个字符';
                    }
                }
            });
                //监听提交
            form.on('submit(formDemo)', function (data) {
                debugger;
                $.ajax({
                    url: '/Goods_Equipment/Add',
                    method: 'post',
                    data: data.field,
                    success: function (data) {

                        if (data == "ok") {
                         layer.alert("添加成功！");
                            setTimeout(function () {
                                window.parent.location = "/Goods_Equipment/InputIndex";
                            }, 2000);


                        } else {
                            layer.alert("添加失败");
                        }
                    }
                });
                return false;//防止页面跳转
            });
        });
    </script>

</body>
</html>